package com.pkk.penguin.frame.know.java.driven.aop;

import com.pkk.penguin.frame.know.java.driven.aop.handle.AopHandle;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * aop的主测试类
 * <p>
 * AOP:【动态代理】:就是指程序在运行期间时将指定带来切入到我们要运行的代码的某个方法的某个位置并运行
 * <p>
 * 1.需要[spring-aspects]的支持
 *
 * @author peikunkun
 * @version V1.0
 * @date 2020-10-14 11:21
 **/
/*相当于配置*/
@EnableAspectJAutoProxy
@ComponentScan("com.pkk.penguin.frame.know.java.driven.aop")
public class AopMainTests {

  public static void main(String[] args) {
    try {
      mode1();
    } catch (Exception e) {
    }
    System.out.println("-------------分割线------------");
    try {
      //mode2();
    } catch (Exception e) {
    }
  }


  /**
   * 方式一【spring容器管理】
   *
   * @return int
   * @Param
   * @author peikunkun
   * @date 2020/10/14 0014 下午 2:53
   * @since
   */
  public static int mode1() {
    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AopMainTests.class);
    final AopHandle bean = applicationContext.getBean(AopHandle.class);
    return bean.execute(1, 0);
  }


  /**
   * 方式二【不受spring容器管理,自定义】
   *
   * @return int
   * @Param
   * @author peikunkun
   * @date 2020/10/14 0014 下午 2:53
   * @since
   */
  public static int mode2() {
    AopHandle aopHandle = new AopHandle();
    return aopHandle.execute(1, 0);
  }

}
